// --------------首页---------------
myApp.controller('VHome', function($scope, $http, $location, $sce, executeCommand, firstThumbnail, firstFilePath, stateService) {

	//Contant1

	//当前状态
	$scope.context = {

		//当前的所有列表数据
		data: [],

		//当前页码
		page: 1,

		//每页返回多少条记录
		size: 9,

		//记录总页
		total: 999,

		//是否正在加载数据
		loading: false,
	};
	$scope.pos = 0;
	$scope.loadMore = function() {
		if($scope.context.total <= $scope.context.size * ($scope.context.page - 1)) return;

		//限制滚动过程重复加载的问题
		if($scope.context.loading) return;
		if($scope.context.data.length >= 9) {
			return;
		}
		$scope.context.loading = true;
		executeCommand('Pub.LoadAdProduct', {
			PositionCode: 'HOME_XV_TJ',
			PageSize: $scope.context.size,
			PageIndex: $scope.context.page
		}, function(result) {
			for(i = 0; i < result.Result.List.length; i++) {
				result.Result.List[i].PhotoUrl = firstThumbnail(result.Result.List[i].PhotoUrl)
				$scope.context.data.push(result.Result.List[i])
			}
			$scope.context.loading = false;
			$scope.context.page = $scope.context.page + 1;
			$scope.context.total = result.TotalCount;
		});
	}
	//Contant2

	//当前状态
	$scope.context2 = {

		//当前的所有列表数据
		data: [1],

		//当前页码
		page: 1,

		//每页返回多少条记录
		size: 6,

		//记录总页
		total: 999,

		//是否正在加载数据
		loading: false,
	};
	$scope.loadNew = function() {
		if($scope.context2.total <= $scope.context2.size * ($scope.context2.page - 1)) return;
		//限制滚动过程重复加载的问题
		if($scope.context2.loading) return;
		if($scope.context2.data.length >= 6) {
			return;
		}
		$scope.context2.loading = true;
		executeCommand('Pub.LoadAdProduct', {
			PositionCode: 'HOME_XV_NEW',
			PageSize: $scope.context2.size,
			PageIndex: $scope.context2.page
		}, function(result) {
			for(i = 0; i < result.Result.List.length; i++) {
				result.Result.List[i].PhotoUrl = firstThumbnail(result.Result.List[i].PhotoUrl)
				$scope.context2.data.push(result.Result.List[i])
			}
			$scope.context2.loading = false;
			$scope.context2.page = $scope.context2.page + 1;
			$scope.context2.total = result.TotalCount;
		});
	}

	//Contant3  

	//当前状态
	$scope.context3 = {

		//当前的所有列表数据
		data: [],

		//当前页码
		page: 1,

		//每页返回多少条记录
		size: 18,

		//记录总页
		total: 999,

		//是否正在加载数据
		loading: false,
	};
	$scope.loadHot = function() {
		if($scope.context3.total <= $scope.context3.size * ($scope.context3.page - 1)) return;

		//限制滚动过程重复加载的问题
		if($scope.context3.loading) return;
		$scope.context3.loading = true;

		executeCommand('Pub.LoadAdProduct', {
			PositionCode: 'HOME_NH',
			PageSize: $scope.context3.size,
			PageIndex: $scope.context3.page
		}, function(result) {
			for(i = 0; i < result.Result.List.length; i++) {
				result.Result.List[i].PhotoUrl = firstThumbnail(result.Result.List[i].PhotoUrl)
				$scope.context3.data.push(result.Result.List[i])
			}
			$scope.context3.loading = false;
			$scope.context3.page = $scope.context3.page + 1;
			$scope.context3.total = result.TotalCount;
			if($scope.context3.total <= $scope.context3.size * ($scope.context3.page - 1)) {
				$('.xiaovstyle3last').css('padding-bottom', '0')
			}
		});
	}

	//Contant4

	//当前状态
	$scope.context4 = {

		//当前的所有列表数据
		data: [],

		//当前页码
		page: 1,

		//每页返回多少条记录
		size: 10,

		//记录总页
		total: 999,

		//是否正在加载数据
		loading: false,
	};

	//Contant5

	//当前状态
	$scope.context5 = {

		//当前的所有列表数据
		data: [],

		//当前页码
		page: 1,

		//每页返回多少条记录
		size: 3,

		//记录总页
		total: 999,

		//是否正在加载数据
		loading: false,
	};

	// 计算定时器
	$scope.now = new Date();
	$scope.today = $scope.now.getDay();
	// console.log($scope.today)
	// var days = $scope.now.toLocaleDateString().replace(/-/g, '/');
	// window.$scope = $scope;
	$scope.ShowWeekSale = false;
	$scope.dqcountdown = '';

	var dqcountdownInit = function() {

		if($scope.today == 4 || $scope.today == 5 || $scope.today == 6) {
			$scope.ShowWeekSale = true;
		};
		// if($scope.today ==4){$scope.ShowWeekSale = false;return};

		//特惠倒计时
		var count = 6 - $scope.today;
		$scope.GetDateStr = function(AddDay) {
			var dd = $scope.now;
			dd.setDate(dd.getDate() + AddDay);
			var y = dd.getFullYear();
			var m = dd.getMonth() + 1; //获取当前月份的日期 
			var d = dd.getDate();
			var dayss = y + "/" + m + "/" + d
			return dayss
		}
		var days = $scope.GetDateStr(count);
		var countDownTime = days + ' 23:59:59';

		$('body').unbind().countdown(countDownTime).on('update.countdown', function(event) {
			$scope.dqcountdown = $sce.trustAsHtml(event.strftime('<span>%D</span>天<span>%H</span>时<span>%M</span>分<span>%S</span>秒'));
			$scope.$apply();
			// var $this = $(this).html(event.strftime('<span>%D</span>天<span>%H</span>时<span>%M</span>分<span>%S</span>秒'));
		}).on('finish.countdown', function() {
			$scope.ShowWeekSale = false;
		});

	};

	dqcountdownInit();

	$scope.WeeklySale = function() {

		if($scope.context5.total <= $scope.context5.size * ($scope.context5.page - 1)) return;
		//限制滚动过程重复加载的问题
		if($scope.context5.loading) return;
		$scope.context5.loading = true;
		executeCommand('Pub.LoadAdProduct', {
			PositionCode: 'HOME_DISCOUNT_PORT',
			PageSize: $scope.context5.size,
			PageIndex: $scope.context5.page
		}, function(result) {
			if(result.Result.List.length > 0) {
				for(i = 0; i < result.Result.List.length; i++) {
					result.Result.List[i].PhotoUrl = firstThumbnail(result.Result.List[i].PhotoUrl)
					$scope.context5.data.push(result.Result.List[i])
				}
				$scope.context5.loading = false;
				$scope.context5.page = $scope.context5.page + 1;
				$scope.context5.total = result.TotalCount;
			};

		});
	}

	executeCommand('Pub.LoadAdProduct', {
		PositionCode: 'HOME_BANNER',
		PageSize: $scope.context4.size,
		PageIndex: $scope.context4.page
	}, function(result) {
		for(i = 0; i < result.Result.List.length; i++) {
			result.Result.List[i].PhotoUrl = firstThumbnail(result.Result.List[i].PhotoUrl)
			$scope.context4.data.push(result.Result.List[i])
		}
	});

	//当前状态
	$scope.context6 = {

		//当前的所有列表数据
		data: [],

		//当前页码
		page: 1,

		//每页返回多少条记录
		size: 10,

		//记录总页
		total: 999,

		//是否正在加载数据
		loading: false,
	};

	executeCommand('Pub.LoadAdProduct', {
		PositionCode: 'HOME_MIDDLE_BANNER',
		PageSize: $scope.context6.size,
		PageIndex: $scope.context6.page
	}, function(result) {
		for(i = 0; i < result.Result.List.length; i++) {
			if(result.Result.List[i].PhotoUrl.indexOf('.gif') < 0) {
				result.Result.List[i].PhotoUrl = firstThumbnail(result.Result.List[i].PhotoUrl);
			} else {
				result.Result.List[i].PhotoUrl = firstFilePath(result.Result.List[i].PhotoUrl);
			}
			$scope.context6.data.push(result.Result.List[i])
		}
	});

	//当前状态
	$scope.context9 = {

		//当前的所有列表数据
		data: [],

		//当前页码
		page: 1,

		//每页返回多少条记录
		size: 10,

		//记录总页
		total: 999,

		//是否正在加载数据
		loading: false,
	};

	executeCommand('Pub.LoadAdProduct', {
		PositionCode: 'HOME_MIDDLE_BANNER_BIG',
		PageSize: $scope.context9.size,
		PageIndex: $scope.context9.page
	}, function(result) {
		for(i = 0; i < result.Result.List.length; i++) {
			if(result.Result.List[i].PhotoUrl.indexOf('.gif') < 0) {
				result.Result.List[i].PhotoUrl = firstThumbnail(result.Result.List[i].PhotoUrl);
			} else {
				result.Result.List[i].PhotoUrl = firstFilePath(result.Result.List[i].PhotoUrl);
			}
			$scope.context9.data.push(result.Result.List[i])
		}
	});

	//当前状态
	$scope.context7 = {

		//当前的所有列表数据
		data: [],

		//当前页码
		page: 1,

		//每页返回多少条记录
		size: 10,

		//记录总页
		total: 999,

		//是否正在加载数据
		loading: false,
	};

	executeCommand('Pub.LoadAdProduct', {
		PositionCode: 'HOME_CATE_PARTITION',
		PageSize: $scope.context7.size,
		PageIndex: $scope.context7.page
	}, function(result) {
		var arr = [];
		for(i = 0; i < result.Result.List.length; i++) {
			var item = result.Result.List[i];
			item.PhotoUrl = firstThumbnail(item.PhotoUrl);
			arr.push(result.Result.List[i])
		}

		$scope.context7.data = arr;
	});

	//当前状态
	$scope.context8 = {

		//当前的所有列表数据
		data: [],

		//当前页码
		page: 1,

		//每页返回多少条记录
		size: 10,

		//记录总页
		total: 999,

		//是否正在加载数据
		loading: false,
	};

	executeCommand('Pub.LoadAdProduct', {
		PositionCode: 'HOME_XV_PARTITION',
		PageSize: $scope.context8.size,
		PageIndex: $scope.context8.page
	}, function(result) {
		var arr = [];
		for(i = 0; i < result.Result.List.length; i++) {
			var item = result.Result.List[i];
			item.PhotoUrl = firstThumbnail(item.PhotoUrl);
			arr.push(result.Result.List[i])
		}
		$scope.context8.data = arr;
//		console.log($scope.context)//返回的数据
	});

	$scope.fubiao = null;
	executeCommand('Pub.LoadAdProduct', {
		PositionCode: 'HOME_FLOAT_BANNER',
		PageSize: 1,
		PageIndex: 1
	}, function(result) {
		var item = result.Result.List[0];
		if(!item) {
			return;
		}
		item.PhotoUrl = firstFilePath(item.PhotoUrl);
		$scope.fubiao = item;
	});

	//弹出层
	executeCommand('Pub.LoadAdProduct', {
		PositionCode: 'HOME_LAYER',
		PageSize: 1,
		PageIndex: 1
	}, function(result) {
		var item = result.Result.List[0];
		if(item) {
			item.PhotoUrl = firstFilePath(item.PhotoUrl)
			LoadAlelt(item);
		}
	});

	$scope.trackEvent = function(item) {
		var path = 'default|home|' + item.PositionCode + '|' + item.Id; //路径
		_hmt.push(['_trackEvent', path, 'click', item.Title])
	};

	$(window).bind('scroll', function() {
		$scope.pos = $(window).scrollTop()
		if($scope.pos > 700) {
			$('.gotop').show()
		} else {
			$('.gotop').hide()
		}
		//保存pos
		stateService.save('VHome', $scope, ['pos']);
	});

	$(document).ready(function() {
		$.cookie('After', $.cookie('CurrentPage'));
		$.cookie('CurrentPage', 'default');
		var After = $.cookie('After');
		var Current = $.cookie('CurrentPage');
		//保存统计记录
		var path = 'default|path|' + Current + '|' + After;
		_hmt.push(['_trackEvent', path, 'enter', 'default']);

		//        //店庆倒计时
		//        var countDownTime = '2017/05/01 00:00:00';
		//        $('div.dqcountdown').unbind().countdown(countDownTime).on('update.countdown', function (event) {
		//            var $this = $(this).html(event.strftime('<span>%D</span>天<span>%H</span>时<span>%M</span>分<span>%S</span>秒'));
		//        }).on('finish.countdown', function () {
		//            var countDownTime = '2017/05/08 00:00:00';
		//            $('.productTime .stateTime').html('距离店庆结束还有');
		//            $('div.dqcountdown').unbind().countdown(countDownTime).on('update.countdown', function (event) {
		//            var $this = $(this).html(event.strftime('<span>%D</span>天<span>%H</span>时<span>%M</span>分<span>%S</span>秒'));
		//            }).on('finish.countdown', function () {
		//                $('.productTime').hide();
		//            });
		//        })

	});

	$scope.$on('ngRepeatFinished', function(ngRepeatFinishedEvent, attr) {
		$('img.lazy').scrollLoading();
		//导航条滑动
		var mySwiper2 = new Swiper('.thumb', {
			freeMode: true, //自由活动
			freeModeFluid: true, //释放滑块之后仍会滑动一小会
			slidesPerView: 'auto', //会根据容器container的宽度调整slides数目
		});

		if(attr.onFinishRenderFilters == 'context4') {
			//轮播图
			$('.bannerthumb').swiper({
				loop: true,
				autoplay: 6000,
				autoplayDisableOnInteraction: false,
				followFinger: true,
				pagination: ".swiper-pagination",
				//其他设置
			});
		} else {
			//保存context
			stateService.save('VHome', $scope, [attr.onFinishRenderFilters]);
		}
	});

	$scope = stateService.load('VHome', $scope, ['context', 'context2', 'context3', 'pos']);
	//还原状态
	if($scope.pos > 0) {
		$('body,html').animate({
			scrollTop: $scope.pos
		}, 500)
	}

	//删除滚动事件
	$scope.$on('$destroy', function() {
		$(window).unbind('scroll');
		// stateService.save('ListControllerSLGS', $scope, ['context','pos'])
	});

	//回到顶部
	$scope.gotop = function() {
		$('body,html').animate({
			scrollTop: 0
		}, 200)
	}

	var isNewUser = $.cookie('isNewUser');
//	console.log(isNewUser);
	if(isNewUser == 'true' || isNewUser == null) {
		executeCommand('Member.CheckNewMember', {}, function(result) {
			if(result.Result.IsNew === true) {
				$.cookie('isNewUser', 'true');
				$scope.footab = {
					Url: 'https://cms.weixinmvp.com/Mass/170921newmember/default.aspx',
					PhotoUrl: 'images/Default/footab.png',
				};
			} else if(result.Result.IsNew === false) {
				$.cookie('isNewUser', 'false');
			}
		});
	}

	$scope.closeFootab = function() {
		$scope.footab = null;
	};

}).filter('to_trusted', ['$sce', function($sce) {
	return function(text) {
		return $sce.trustAsHtml(text);
	}
}])

//----------------------------分类List------------------------------------
myApp.controller('ListController', function($scope, $http, $location, executeCommand, firstThumbnail, stateService) {

	$scope.path = $location.path()
	$scope.bg = {
		'/snsg': '#F9F8F8',
		'/myzq': '#F9F8F8',
		'/mcjs': '#F9F8F8',
		'/spxx': '#F9F8F8',
		'/lszb': '#F9F8F8',
		'/lymm': '#F9F8F8',
		'/jydq': '#F9F8F8'
	};

	//当前状态
	$scope.context7 = {

		//当前的所有列表数据
		data: [],

		//当前页码
		page: 1,

		//每页返回多少条记录
		size: 10,

		//记录总页
		total: 999,

		//是否正在加载数据
		loading: false,
	};

	var PositionCode = 'CATE_CATEGORY_AREA_' + $scope.path.replace(/\//g, '');

	executeCommand('Pub.LoadAdProduct', {
		PositionCode: PositionCode,
		PageSize: $scope.context7.size,
		PageIndex: $scope.context7.page
	}, function(result) {
		var arr = [];
		for(i = 0; i < result.Result.List.length; i++) {
			var item = result.Result.List[i];
			item.PhotoUrl = firstThumbnail(item.PhotoUrl);
			arr.push(result.Result.List[i])
		}

		$scope.context7.data = arr;
	});

	$scope.context = {
		banner: [], //顶部banner

		type: [], //banner下的小分类

		recommendlist: [], //爆款

		newlist: [], //上新

		hotlist: {
			data: [],
			page: 1,
			size: 6,
			total: 999,
			loading: false
		}, //热卖

		pos: 0 //位置

	}

	var cate1 = $location.path(); //$location中包含分类信息
	var cate = cate1.replace(/[/]/, "");
	$scope.cate = cate;

	$scope.trackEvent = function(item) {
		var path = 'default' + '|' + cate + '|' + item.PositionCode + '|' + item.Id; //路径
		_hmt.push(['_trackEvent', path, 'click', item.Title])
	};

	$(window).bind('scroll', function() {
		$scope.context.pos = $(window).scrollTop()
		//保存pos
		stateService.save(cate, $scope.context, ['pos']);
	});

	$(document).ready(function() {
		$.cookie('After', $.cookie('CurrentPage'));
		$.cookie('CurrentPage', cate);
		var After = $.cookie('After');
		var Current = $.cookie('CurrentPage');
		//保存统计记录
		var path = cate + '|path|' + Current + '|' + After;
		_hmt.push(['_trackEvent', path, 'enter', 'default']);
	});

	$scope.$on('ngRepeatFinished', function(ngRepeatFinishedEvent, attr) {
		$('img.lazy').scrollLoading();
		//保存context
		stateService.save(cate, $scope.context, [attr.onFinishRenderFilters])
	});

	//还原状态
	$scope.context = stateService.load(cate, $scope.context, ['banner', 'type', 'hotlist', 'newlist', 'recommendlist', 'pos'])
	if($scope.context.pos > 0) {
		$('body,html').animate({
			scrollTop: $scope.context.pos
		}, 500)
	}

	//banner
	if($scope.context.banner.length == 0) {
		executeCommand('Pub.LoadAdProduct', {
			PositionCode: 'CATE_BN_' + cate,
			PageSize: 1,
			PageIndex: 1
		}, function(result) {
			for(i = 0; i < result.Result.List.length; i++) {
				result.Result.List[i].PhotoUrl = firstThumbnail(result.Result.List[i].PhotoUrl)
				$scope.context.banner.push(result.Result.List[i])
			}
		});
	}

	//type
	if($scope.context.type.length == 0) {
		executeCommand('Pub.LoadAdProduct', {
			PositionCode: 'CATE_TP_' + cate,
			PageSize: 10,
			PageIndex: 1
		}, function(result) {
			for(i = 0; i < result.Result.List.length; i++) {
				result.Result.List[i].PhotoUrl = firstThumbnail(result.Result.List[i].PhotoUrl);
				$scope.context.type.push(result.Result.List[i]);
			};
		});
	}

	//recommendlist
	if($scope.context.recommendlist.length == 0) {
		executeCommand('Pub.LoadAdProduct', {
			PositionCode: 'CATE_TJ_' + cate,
			PageSize: 9,
			PageIndex: 1
		}, function(result) {
			if(result.Result.List.length == 0) {
				return;
			} else {
				for(i = 0; i < result.Result.List.length; i++) {
					result.Result.List[i].PhotoUrl = firstThumbnail(result.Result.List[i].PhotoUrl)
					$scope.context.recommendlist.push(result.Result.List[i])
				}
			}
		});

	}

	//hotlist
	$scope.loadHot = function() {
		if($scope.context.hotlist.total <= $scope.context.hotlist.size * ($scope.context.hotlist.page - 1)) return;

		//限制滚动过程重复加载的问题
		if($scope.context.hotlist.loading) return;
		$scope.context.hotlist.loading = true;

		executeCommand('Pub.LoadAdProduct', {
			PositionCode: 'CATE_HOT_' + cate,
			PageSize: $scope.context.hotlist.size,
			PageIndex: $scope.context.hotlist.page
		}, function(result) {
			if(result.Result.List.length == 0) {
				return;
			} else {
				for(i = 0; i < result.Result.List.length; i++) {
					result.Result.List[i].PhotoUrl = firstThumbnail(result.Result.List[i].PhotoUrl)
					$scope.context.hotlist.data.push(result.Result.List[i])
				}
				$scope.context.hotlist.loading = false;
				$scope.context.hotlist.page = $scope.context.hotlist.page + 1;
				$scope.context.hotlist.total = result.TotalCount;
			}
		});

	}

	//newlist
	if($scope.context.newlist.length == 0) {
		executeCommand('Pub.LoadAdProduct', {
			PositionCode: 'CATE_NEW_' + cate,
			PageSize: 6,
			PageIndex: 1
		}, function(result) {
			if(result.Result.List.length == 0) {
				return;
			} else {
				for(i = 0; i < result.Result.List.length; i++) {
					result.Result.List[i].PhotoUrl = firstThumbnail(result.Result.List[i].PhotoUrl)
					$scope.context.newlist.push(result.Result.List[i])
				}
			}
		});
	}

	//删除滚动事件
	$scope.$on('$destroy', function() {
		$(window).unbind('scroll');
		// stateService.save('ListControllerSLGS', $scope, ['context','pos'])
	});

}).filter('to_trusted', ['$sce', function($sce) {
	return function(text) {
		return $sce.trustAsHtml(text);
	}
}])

// myApp.controller('doubleElevenController', function ($scope, $element, $http, executeCommand, firstThumbnail, firstFilePath) {

//     /** 保留两位小数 */
//     var fomatFloat = function(x) {
//         var f = parseFloat(x);
//         if (isNaN(f)) {
//             return false;
//         }
//         var f = Math.round(x * 100) / 100;
//         var s = f.toString();
//         var rs = s.indexOf('.');
//         if (rs < 0) {
//             rs = s.length;
//             s += '.';
//         }
//         while (s.length <= rs + 2) {
//             s += '0';
//         }
//         return s;
//     };

//     var getProductList = function (id, limit, callback, PromotionStatus) {
//         $http({
//             url: "https://cms.weixinmvp.com/api/Product/GetReferenceProductList",
//             // url: "http://192.168.0.32:8006/api/Product/GetReferenceProductList",
//             // url: "http://192.168.0.101:8005/api/Product/GetReferenceProductList",
//             method: 'post',
//             data: {
//                 "ReferenceKind": "article",
//                 "PromotionStatus": PromotionStatus,
//                 "ReferenceCode": id,
//                 "PageIndex": 1,
//                 "PageSize": limit || 99
//             }
//         }).then(function($res) {
//             var productList = $res.data.Data;
//             for(i=0;i<productList.length;i++){
//                 productList[i].ProductImage = firstThumbnail(productList[i].ProductImage);
//                 productList[i].SalePriceFloat = fomatFloat(productList[i].SalePrice);
//                 productList[i].SalePriceFormat = (productList[i].SalePriceFloat).split('.');
//             }
//             return callback && callback(productList);
//         }, function () {

//         });
//     };

//     $scope.bannerList = [];

//     $scope.productXlList = [];
//     $scope.productTjList = [];
//     $scope.productList = [
//         {

//             kind: 'd_g',
//             id: 376,
//             limit: 12,
//             titleImg: '../Shop/css/images/double_eleven/double_eleven_05.png',
//             difference: -10,
//             mt: 10,
//             label: ['2', '2', '2', '2', '2', '2', '2', '2', '2', '1', '1', '1'],
//             list: [],
//             // more: {
//             //     kind: 'd',
//             //     id: 376,
//             //     limit: 3,
//             //     list: []
//             // },
//         }, {

//             kind: 's',
//             id: 378,
//             limit: 12,
//             titleImg: '../Shop/css/images/double_eleven/double_eleven_14.png',
//             difference: 40,
//             mt: 0,
//             label: ['3', '3', '3', '1', '1', '1', '1', '1', '1', '1', '1', '1'],
//             list: []
//         }, {
//             kind: 'h',
//             id: 379,
//             limit: 12,
//             titleImg: '../Shop/css/images/double_eleven/double_eleven_12.png',
//             difference: 40,
//             mt: 0,
//             label: ['3', '3', '3', '1', '1', '1', '1', '1', '1', '1', '1', '1'],
//             list: []
//         }, {
//             kind: 'k',
//             id: 377,
//             limit: 12,
//             titleImg: '../Shop/css/images/double_eleven/double_eleven_10.png',
//             difference: 50,
//             mt: 0,
//             label: ['3', '3', '3', '1', '1', '1', '1', '1', '1', '1', '1', '1'],
//             list: []
//         }

//     ];

//     getProductList(380, 3, function (productList) {
//         $scope.productXlList = productList;
//         for (var i = 0; i < productList.length; i++) {
//             productList[i].label = '4';
//             productList[i].Param2 = Number(productList[i].Param2);
//             if (!productList[i].SaleCount) {
//                 productList[i].schedule = 0;
//             } else if (!productList[i].Param2 || isNaN(productList[i].Param2) || productList[i].SaleCount >= productList[i].Param2) {
//                 productList[i].schedule = 100;
//             } else {
//                 var aValue = 0;
//                 if(productList[i].Param3){
//                     aValue = parseInt(productList[i].Param3);
//                 }
//                 productList[i].schedule = Math.round( (productList[i].SaleCount + aValue) / productList[i].Param2 * 100);
//             }
//         }
//     }, 1);

//     getProductList(381, 3, function (productList) {
//         $scope.productTjList = productList;
//         for (var i = 0; i < productList.length; i++) {
//             productList[i].label = '4';
//             productList[i].Param2 = Number(productList[i].Param2);
//             productList[i].Param3 = Number(productList[i].Param3);
//             if (!isNaN(productList[i].Param3)) {
//                 productList[i].SaleCount += productList[i].Param3;
//             }
//             if (!productList[i].SaleCount) {
//                 productList[i].schedule = 0;
//             } else if (!productList[i].Param2 || isNaN(productList[i].Param2) || productList[i].SaleCount >= productList[i].Param2) {
//                 productList[i].schedule = 100;
//             } else {
//                 productList[i].schedule = Math.round(productList[i].SaleCount / productList[i].Param2 * 100);
//             }
//         }
//     });

//     $.each($scope.productList, function(index, opt) {
//         getProductList(opt.id, opt.limit, function (productList) {
//             opt.list = productList;
//             for (var i = 0; i < productList.length; i++) {
//                 productList[i].label = opt.label[i] || '1';
//             }

//             if (opt.more) {
//                 getProductList(opt.more.id, opt.more.limit, function (productList) {
//                     opt.more.list = productList;
//                     for (var j = 0; j < productList.length; j++) {
//                         productList[j].label = opt.label[i + j] || '1';
//                     }
//                 });
//             } else {
//             }
//         });
//     });

//     $scope.trackEvent = function(item){
//         var path ='default|home|'+item.PositionCode+'|'+item.Id;//路径
//         _hmt.push(['_trackEvent',path,'click',item.Title])
//     };

//     $scope.statistics = function (name, src) {
//         var path = 'default|double_eleven|' + src.join('|');//路径
//         _hmt.push(['_trackEvent', path, 'click', name]);
//     };

//     executeCommand('Pub.LoadAdProduct', {
//         PositionCode: 'HOME_BANNER',
//         PageSize: 10,
//         PageIndex: 1
//     }, function(result){
//         for(i=0;i<result.Result.List.length;i++){
//             result.Result.List[i].PhotoUrl = firstThumbnail(result.Result.List[i].PhotoUrl);
//             $scope.bannerList.push(result.Result.List[i])
//         }
//     });

//     $scope.$on('ngRepeatFinished', function (ngRepeatFinishedEvent, attr) {
//         $element.find('[on-finish-render-filters="' + attr.onFinishRenderFilters + '"]').find('img.lazy').scrollLoading();
//         if(attr.onFinishRenderFilters == 'bannerList'){
//             //轮播图
//             $element.find('.bannerthumb').swiper({
//                 loop: true,
//                 autoplay:6000,
//                 autoplayDisableOnInteraction:false,
//                 followFinger: true,
//                 pagination:".swiper-pagination",
//                 //其他设置

//                 effect: "coverflow",
//                 spaceBetween: 32,
//                 centeredSlides: true,
//                 slidesPerView: 1.2,
//                 loopedSlides: 2,
//                 coverflow: {
//                     rotate: 0,
//                     slideShadows: false,
//                     stretch: 0,
//                     depth: 150,
//                     modifier: 1
//                 },
//                 onSlideChangeEnd: function (swiper) {
//                     var $img = $('.topbanner .swiper-slide').eq(swiper.activeIndex).find('img');
//                     if ($img.length) {
//                         var src = $img.attr('src');
//                         $('.topbanner .bg').attr('src', src);
//                     }
//                 }
//             });
//         };
//     });

//     $scope.fubiao = null;
//     executeCommand('Pub.LoadAdProduct', { PositionCode: 'HOME_FLOAT_BANNER', PageSize: 1, PageIndex:  1 }, function(result){
//         var item = result.Result.List[0];
//         if (!item) { return ; }
//         item.PhotoUrl = firstFilePath(item.PhotoUrl);
//         $scope.fubiao = item;
//     });

//     $scope.pos = 0;
//     $(window).bind('scroll', function() {
//         $scope.pos = $(window).scrollTop();
//         $scope.$apply();
//     });

//     //删除滚动事件
//     $scope.$on('$destroy', function() {
//         $(window).unbind('scroll');
//     });

//     //回到顶部
//     $scope.gotop = function(){
//         $('body,html').animate({scrollTop:0},200)
//     }

//     $scope.anchor = function (anchor) {
//         var $anchor = $element.find('[data-anchor="' + anchor + '"]');
//         if (!$anchor.length) { return ; }
//         var $screen = $('html, body');
//         var difference = $anchor.data('difference') || 0;
//         scrollTop = $anchor.offset().top - $('nav').height() + difference;
//         $screen.each(function(index, el) {
//             if($(el).scrollTop() !== scrollTop) {
//                 $(el).animate({
//                     scrollTop: scrollTop || 0
//                 }, 600);
//             }
//         });
//     };

// });